package com.guochu.pro.service.impl;

import com.guochu.pro.entity.Transaction;
import com.guochu.pro.dao.TransactionDao;
import com.guochu.pro.entity.TransactionVO;
import com.guochu.pro.service.TransactionService;
import com.guochu.utils.Pagination;
import com.guochu.common.infrastructure.IService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 产品分类表(Transaction)表服务实现类
 *
 * @author makejava
 * @since 2021-11-04 00:02:39
 */
@Service
public class TransactionServiceImpl extends IService implements TransactionService {
    @Resource
    private TransactionDao transactionDao;

    /**
     * 新增数据
     *
     * @param transaction 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(Transaction transaction) {
        this.create(transaction);
        return this.transactionDao.insert(transaction);
    }
    
    /**
     * 修改数据
     *
     * @param transaction 实例对象
     * @return 实例对象
     */
    @Override
    public int update(Transaction transaction) {
        return this.transactionDao.update(transaction);
    }
    
    /**
     * 逻辑删除多条记录
     *
     * @param idList 主键
     * @return
     */
    @Override
    public int removeByIds(List<String> idList) {
        return this.transactionDao.removeByIds(idList);
    }
    
    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Transaction queryById(String id) {
        return this.transactionDao.queryById(id);
    }

    /**
     * 根据条件查询分页数据
     *
     * @param pagination 分页条件
     * @param limit 查询条件
     * @return 分页数据
     */
    @Override
    public List<TransactionVO> queryPageByLimit(Pagination pagination, Map<String, Object> limit){
        pagination.setTotal(this.transactionDao.recordCount(limit));
        limit.put("offset", (pagination.getCurrentPage() - 1) * pagination.getPageSize());
        limit.put("pageSize", pagination.getPageSize());
        return this.transactionDao.queryPageByLimit(limit);
    }
    
    /**
     * 根据条件查询全部数据
     *
     * @param limit 查询条件
     * @return 所有数据
     */
    @Override
    public List<Transaction> queryAllByLimit(Map<String, Object> limit) {
        return this.transactionDao.queryAllByLimit(limit);
    }
}
